<?php 

$vrsta = "";
$haplotip ="";
$nokgen = "";
$transgen ="";
$soj ="";
$listaMiseva="";
$result="";
$isAdmin = isAdmin();


$pretragaForm = "
	<div class='content' style=\"width: 700px\">
	<span class='contentTitle'> Pretraga miševa </span>
	<form method='POST' action='misevi.php?action=pretraga'>
	<table cellspacing='0'> <tr><td>
	<table class='tableResult'>
		<tr>
			<th scope='col' class='spec' style='width: 100px'> Vrsta </th>
			<td style='width: 50px'>		
				<select name='miseviVrsta' style='width:100%'>
					<option></option>
					<option value='mis'> miš </option>
					<option value='stakor'> štakor </option>
				</select>
			</td>
		</tr>
		
		<tr>
			<th scope='col' class='spec'> Nokautirani gen </th>	
			<td>
				<select name='miseviNokgen' style='width:100%'>";
$pretragaForm .= printOptionsOfAtributes("nokgen", "naziv", 1);
$pretragaForm .= "</select>
			</td>
		</tr>
	</table>
	</td>
	
	<td>	 
	<table class='tableResult'>
		<tr>
			<th scope='col' class='spec'> Soj </th> 
			<td>
				<select name='miseviSoj' style='width:100%'>";
$pretragaForm .= printOptionsOfAtributes("soj", "naziv", 1);        
$pretragaForm .= "</select>
			</td>
		</tr>
		
		<tr>
			<th scope='col' class='spec'> Transgen </th> 
			<td>
				<select name='miseviTransgen' style='width:100%'>";
$pretragaForm .= printOptionsOfAtributes("transgen", "naziv", 1);
$pretragaForm .= "</select>	
			</td>
		</tr>
		

	</table>
	</td>
	
	<td>
	<table class='tableResult'>
		<tr>
			<th scope='col' class='spec'> Haplotip </th>
			<td>	
				<select name='miseviHaplotip' style='width:100%'>";
$pretragaForm .= printOptionsOfAtributes("haplotip", "naziv", 1);

$pretragaForm .= "</select>
			</td>
		</tr>
		
		<tr>
			<th scope='col' class='spec' colspan='2'>
				<center><input type='submit' value='Pretraži' ></center>	
			</th>
		</tr>
	</table>
	</td>
	</tr>
	</table>
	</div><br>
";

if (isset($_POST['miseviVrsta'])) {
	
	$vrsta = $_POST['miseviVrsta'];
	$haplotip = $_POST['miseviHaplotip'];
	$nokgen = $_POST['miseviNokgen'];
	$transgen = $_POST['miseviTransgen'];
	$soj = $_POST['miseviSoj'];
	
	$query = "
			SELECT mis.id AS id, mis.naziv AS vrsta, 
			haplotip.naziv AS haplotip, nokgen.naziv AS nokgen, 
			transgen.naziv AS transgen, soj.naziv AS soj,
			mis.info AS info FROM mis 
			INNER JOIN haplotip ON mis.haplotip = haplotip.id 
			INNER JOIN nokgen ON mis.nokgen = nokgen.id 
			INNER JOIN transgen ON mis.transgen = transgen.id
			INNER JOIN soj ON mis.soj = soj.id
			WHERE 
			mis.naziv LIKE '%" . $vrsta . "%' AND
			haplotip.naziv LIKE '%" . $haplotip . "%' AND
			nokgen.naziv LIKE '%" . $nokgen . "%' AND
			transgen.naziv LIKE '%" . $transgen . "%' AND
			soj.naziv LIKE '%" . $soj . "%'
		";
	$result = myQuery($query);
	
	$listaMiseva .= "
			<div class='content'>
				<span class='contentTitle'> Lista miševa </span>
				<table class='tableResult' cellspacing='0' width='100%'><tr>
				<th scope='col' width='100px'> Vrsta </th> 
				<th scope='col' width='100px'> Soj </th>
				<th scope='col' width='100px'> Haplotip </th> 
				<th scope='col' width='100px'> Transgen </th>
				<th scope='col' width='130px'> Nokautirani gen </th>
				<th scope='col' width='270px'> Info </th>";
	
	while ( $row = mysql_fetch_array($result) ) {
		$listaMiseva .= "
			<tr>
				<td> " . $row['vrsta'] . "</td>
				<td> " . $row['soj'] . "</td>
				<td> " . $row['haplotip'] . "</td>
				<td> " . $row['transgen'] . "</td>
				<td> " . $row['nokgen'] . "</td>
				<td> " . $row['info'] . "</td>";
	
		if ($isAdmin) $listaMiseva .= "
				<td width='16px'> <a title='Promijeni miša' href='misevi.php?action=edit&type=mis&id=" . $row['id'] . "'> 
					<img src='/images/edit.png' width='16px' height='16px'> </a> </td>
				<td width='16px'> <a title='Pobriši miša' href='exec/misevi.php?action=delete&type=mis&id=" . $row['id'] . "'> 
						<img src='/images/delete.png' width='16px' height='16px'> </td>";
		
		$listaMiseva .= "</tr>";
	}
}

$listaMiseva .= "</table></div>";

print($pretragaForm);
print($listaMiseva);

?>
